<html>

<head>

<?php

include "../includes/constants.php";
include "../includes/functions.php";

?>

<title>EQ Emu - Zones</title>

</head>

<body>


<table border="1">
<?php

$query2 = "SELECT DISTINCT min_status FROM zone ORDER BY min_status ASC";
$result2 = mysql_query($query2,$db);
$db_row2 = mysql_fetch_array($result2);
do {
	echo "<a href=\"?min_status=" . $db_row2[min_status] . "\">" . $db_row2[min_status] . "</a> ";
} while ($db_row2 = mysql_fetch_array($result2));

?>
	<tr>
		<th><?php SortLink(zoneidnumber,'ID');?></th>
		<th><?php SortLink(short_name,'Zone');?></th>
		<th><?php SortLink(long_name,'Zone Title');?></th>
		<th><?php SortLink(min_level,'Min Level');?></th>
		<th><?php SortLink(min_status,'Min Status');?></th>
		<th><?php SortLink(flag_needed,'Flag/Key');?></th>
	</tr>
<?php

$query1 = "SELECT * FROM zone ";
// if (!isset($_GET[min_status])) $_GET[min_status] = 0;
if (isset($_GET[min_status]) && ($_GET[min_status] != "")) $query1 .= " WHERE min_status='" . $_GET[min_status] . "' ";
if (!isset($_GET[sort]) || ($_GET[sort] == "")) $_GET[sort] = "short_name";
if (!isset($_GET[dir]) || ($_GET[dir] == "")) $_GET[dir] = "ASC";
$query1 .= " ORDER BY " . $_GET[sort] . " " . $_GET[dir] . " ";
// $query1 .= " LIMIT 10 OFFSET 0 ";
$result1 = mysql_query($query1,$db);

if ($db_row1 = mysql_fetch_array($result1)) {
	do {
		echo "\t<tr>
		<td align=\"right\">" . $db_row1[zoneidnumber] . "</td>
		<td>" . $db_row1[short_name] . "</td>
		<td>" . $db_row1[long_name] . "</td>
		<td align=\"right\">" . $db_row1[min_level] . "</td>
		<td align=\"right\">" . $db_row1[min_status] . "</td>\n";
		if ($db_row1[flag_needed] == 1) $db_row1[flag_needed] = "Flag";
		echo "\t\t<td align=\"center\">" . $db_row1[flag_needed] . "</td>
	</tr>\n";
	} while ($db_row1 = mysql_fetch_array($result1));
} else {
	echo "\t<tr>
		<td colspan=\"4\">No Results Found.</td>
	</tr>\n";
};

?>
</table>

</body>

</html>